/*

 * Licensed to the Apache Software Foundation (ASF) under one

 * or more contributor license agreements.  See the NOTICE file

 * distributed with this work for additional information

 * regarding copyright ownership.  The ASF licenses this file

 * to you under the Apache License, Version 2.0 (the

 * "License"); you may not use this file except in compliance

 * with the License.  You may obtain a copy of the License at

 *

 *     http://www.apache.org/licenses/LICENSE-2.0

 *

 * Unless required by applicable law or agreed to in writing, software

 * distributed under the License is distributed on an "AS IS" BASIS,

 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 * See the License for the specific language governing permissions and

 * limitations under the License.

 */

package com.bff.gaia.unified.sdk.transforms.xjoin.core.side;

/*

 * Licensed to the Apache Software Foundation (ASF) under one or more

 * contributor license agreements.  See the NOTICE file distributed with

 * this work for additional information regarding copyright ownership.

 * The ASF licenses this file to You under the Apache License, Version 2.0

 * (the "License"); you may not use this file except in compliance with

 * the License.  You may obtain a copy of the License at

 *

 *    http://www.apache.org/licenses/LICENSE-2.0

 *

 * Unless required by applicable law or agreed to in writing, software

 * distributed under the License is distributed on an "AS IS" BASIS,

 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 * See the License for the specific language governing permissions and

 * limitations under the License.

 */



import com.bff.gaia.unified.sdk.schemas.Schema;



/** Description: gaia-parent Created by tiger on 2019/7/18 16:58. */

public class FieldInfo extends Schema.Field {



  private static final long serialVersionUID = -1L;



  private String table;



  private String fieldName;



  private String description;



  private Schema.FieldType type;



  private boolean isJoinKey = false;



  public FieldInfo(Schema.Field field) {

    this.fieldName = field.getName();

    this.description = field.getDescription();

    this.type = field.getType();

  }



  public FieldInfo(

      String table,

      String fieldName,

      String description,

      Schema.FieldType type,

      boolean isJoinKey) {

    this.table = table;

    this.fieldName = fieldName;

    this.description = description;

    this.type = type;

    this.isJoinKey = isJoinKey;

  }



  public String getTable() {

    return table;

  }



  public void setTable(String table) {

    this.table = table;

  }



  @Override

  public String getName() {

    return fieldName;

  }



  public void setFieldName(String fieldName) {

    this.fieldName = fieldName;

  }



  @Override

  public String getDescription() {

    return description;

  }



  public void setDescription(String description) {

    this.description = description;

  }



  @Override

  public Schema.FieldType getType() {

    return type;

  }



  public void setType(Schema.FieldType type) {

    this.type = type;

  }



  public boolean isJoinKey() {

    return isJoinKey;

  }



  public void setJoinKey(boolean joinKey) {

    isJoinKey = joinKey;

  }



  @Override

  public Schema.Field.Builder toBuilder() {

    return new Builder(this);

  }



  static final class Builder extends Schema.Field.Builder {

    private String table;

    private boolean isJoinKey = false;

    private String name;

    private String description;

    private Schema.FieldType type;



    Builder() {}



    private Builder(Schema.Field source) {

      this.name = source.getName();

      this.description = source.getDescription();

      this.type = source.getType();

    }



    @Override

    public Schema.Field.Builder setName(String name) {

      if (name == null) {

        throw new NullPointerException("Null name");

      }

      this.name = name;

      return this;

    }



    @Override

    public Schema.Field.Builder setDescription(String description) {

      if (description == null) {

        throw new NullPointerException("Null description");

      }

      this.description = description;

      return this;

    }



    @Override

    public Schema.Field.Builder setType(Schema.FieldType type) {

      if (type == null) {

        throw new NullPointerException("Null type");

      }

      this.type = type;

      return this;

    }



    public void setTable(String table) {

      this.table = table;

    }



    public void setJoinKey(boolean joinKey) {

      isJoinKey = joinKey;

    }



    @Override

    public Schema.Field build() {

      String missing = "";

      if (this.table == null) {

        missing += " table";

      }

      if (this.name == null) {

        missing += " name";

      }

      if (this.description == null) {

        missing += " description";

      }

      if (this.type == null) {

        missing += " type";

      }

      if (!missing.isEmpty()) {

        throw new IllegalStateException("Missing required properties:" + missing);

      }

      return new FieldInfo(this.table, this.name, this.description, this.type, this.isJoinKey);

    }

  }

}